﻿using System;
using System.IO;
using System.Windows.Forms;
namespace _6.jkxt
{
    public partial class add : Form
    {
        public add()
        {
            InitializeComponent();
        }

        private void yzwAdd_Load(object sender, EventArgs e)
        {
            InitDgvByCustom();
            if (Main.csName.pl[39, 1] == "AZEL")
            {
                fWj.HeaderText = "方位角(°)";
                fYj.HeaderText = "俯仰角(°)";
            }
        }
        private void InitDgvByCustom()
        {

            //预置位置读取
            StreamReader dry = File.OpenText(Environment.CurrentDirectory + "\\text\\txYzwz.txt");
            for (int i = 0; i < 10; i++)
            {
                string line = dry.ReadLine();
                //创建行
                DataGridViewRow drRow1 = new DataGridViewRow();
                drRow1.CreateCells(this.dataGw);
                //设置单元格的值

                drRow1.Cells[0].Value = i + 1;
                if (line != null)
                {
                    string[] strArray = line.Split(',');
                    drRow1.Cells[1].Value = strArray[0];
                    drRow1.Cells[2].Value = strArray[1];
                    drRow1.Cells[3].Value = strArray[2];
                }
                //将新创建的行添加到DataGridView中
                this.dataGw.Rows.Add(drRow1);
            }
            dry.Close();
            //设置DataGridView的属性
            this.dataGw.AllowUserToAddRows = false;//不自动产生最后的新行
        }

        private void add_FormClosed(object sender, FormClosedEventArgs e)
        {
            string z = "";
            for (int i = 0; i < 10; i++)
            {
                string h = "";
                for (int k = 1; k < 4; k++)
                {
                    try
                    {
                        h = h + this.dataGw.Rows[i].Cells[k].Value.ToString() + ",";
                    }
                    catch
                    {
                        h = h + ",";
                    }
                }
                h = h + "左旋\r\n";
                z = z + h;
            }
            File.WriteAllText(Environment.CurrentDirectory + "\\text\\txYzwz.txt", z);
            this.DialogResult = DialogResult.OK;
        }
        //前三行无法编辑
        private void dataGw_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
        {
            DataGridView dgv = (DataGridView)sender;
            if (dgv.CurrentCell.RowIndex < 2)
            {
                e.Cancel = true;//取消编辑为真
            }
        }
    }
}
